﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using Light.Utility;
using System.ComponentModel;

namespace Light.Framework.Model
{
    [ImportField("日志")]
    [ActiveRecord("Logs")]
    public class Log : Entity
    {
        [Property("FType")]
        public LogType LogType { get; set; }

        [ImportField("内容")]
        [Searchable("内容")]
        [Property("FContent")]
        public string Content
        {
            get
            {
                return this.GetValue<string>("Content");
            }
            set
            {
                if (value != null && value.Length > 1000)
                {
                    value = value.Substring(0, 1000);
                }
                this.SetValue("Content", value);
            }
        }

        /// <summary>
        /// IP
        /// </summary>
        [Property]
        [Searchable("IP")]
        public string IPAddress { get; set; }

        /// <summary>
        /// 设备
        /// </summary>
        [Property]
        public string Device { get; set; }

        //[ImportField("用户名")]
        //[Property]
        //public string UserName { get; set; }

        [ImportField("区域")]
        public override Organization Organization { get; set; }

        [ImportField("记录时间")]
        public override DateTime TimeCreated
        {
            get
            {
                return base.TimeCreated;
            }
            set
            {
                base.TimeCreated = value;
            }
        }
    }

    /// <summary>
    /// 日志类型
    /// </summary>
    public enum LogType
    {
        /// <summary>
        /// 登录日志
        /// </summary>
        [Description("登录")]
        Login,

        /// <summary>
        /// 操作日志
        /// </summary>
        [Description("操作")]
        Operation,

        /// <summary>
        /// 错误日志
        /// </summary>
        [Description("错误")]
        Error,

        /// <summary>
        /// 页面访问日志
        /// </summary>
        [Description("访问")]
        Visited
    }
}
